//
//  ForgetCodeViewController.m
//  02-HomeWork
//
//  Created by dllo on 16/7/15.
//  Copyright © 2016年 danming. All rights reserved.
//

#import "ForgetCodeViewController.h"

@interface ForgetCodeViewController ()<UITextFieldDelegate>
@property (nonatomic, strong) UILabel *labelOfTitle;
@property (nonatomic, strong) UILabel *labelOfHint;
@property (nonatomic, strong) UITextField *phoneNumber;
@property (nonatomic, strong) UITextField *securityCode;
@property (nonatomic, strong) UIButton *getCodeButton;
@property (nonatomic, strong) UIButton *nextButton;
@property (nonatomic, strong) UIButton *clickButton;
@property (nonatomic, strong) UIButton *returnButton;
@property (nonatomic, strong) UIImageView *phoneNumber_image;
@property (nonatomic, strong) UIImageView *securityCode_image;
@property (nonatomic, strong) UIView *topLineView;
@property (nonatomic, strong) UIView *bottomLineView;
@end

@implementation ForgetCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createCover];
    [self configNavigationBar];
}
#pragma mark - 设置bar的属性
- (void)configNavigationBar {
    self.navigationItem.title = @"忘记密码";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName :[UIColor whiteColor]}];
}
#pragma mark - 创建封面
- (void)createCover {
    /********** 创建label标题 ***********/
    self.labelOfTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, 50)];
    _labelOfTitle.text = @"验证手机";
    _labelOfTitle.textAlignment = NSTextAlignmentCenter;
    _labelOfTitle.font = [UIFont systemFontOfSize:25];
    _labelOfTitle.textColor = [UIColor blackColor];
    _labelOfTitle.alpha = 0.7f;
    [self.view addSubview:_labelOfTitle];
    /*********** 创建textField ***********/
    self.phoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(10, 110, 394, 50)];
    self.securityCode = [[UITextField alloc] initWithFrame:CGRectMake(10, 160, 394, 50)];
    _phoneNumber.placeholder = @"  手机号 (仅支持中国大陆号)";
    _securityCode.placeholder = @"  验证码";
    _phoneNumber.delegate = self;
    _securityCode.delegate = self;
    _phoneNumber.font = [UIFont systemFontOfSize:20];
    _securityCode.font = [UIFont systemFontOfSize:20];
    _phoneNumber.tag = 1;
    _securityCode.tag = 2;
    // 创建两个小图标
   self.phoneNumber_image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Unknown"]];
    self.securityCode_image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Unknown-2"]];
    _phoneNumber_image.alpha = 0.3f;
    _securityCode_image.alpha = 0.3f;
    // 将两个小图标加到textField得左边
    _phoneNumber.leftView = _phoneNumber_image;
    _securityCode.leftView = _securityCode_image;
    _phoneNumber.leftViewMode = UITextFieldViewModeAlways;
    _securityCode.leftViewMode = UITextFieldViewModeAlways;
    [self.view addSubview:_phoneNumber];
    [self.view addSubview:_securityCode];
    /*********** 创建两个高度为1的view ***********/
    self.topLineView = [[UIView alloc] initWithFrame:CGRectMake(10, 161, 394, 1)];
    self.bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(10, 211, 394, 1)];
    [self.view addSubview:_topLineView];
    [self.view addSubview:_bottomLineView];
    _topLineView.alpha = 0.3f;
    _bottomLineView.alpha = 0.3f;
    _topLineView.backgroundColor = [UIColor blackColor];
    _bottomLineView.backgroundColor = [UIColor blackColor];
     /********** 创建获取验证码button ***********/
    self.getCodeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_getCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    [_getCodeButton setTintColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00]];
    _getCodeButton.frame = CGRectMake(300, 168, 100, 40);
    [self.view addSubview:_getCodeButton];
    /*********** 创建下一步按钮 ***********/
    self.nextButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_nextButton setTitle:@"下一步" forState:UIControlStateNormal];
    _nextButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    [_nextButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    _nextButton.titleLabel.font = [UIFont systemFontOfSize:22];
    _nextButton.frame = CGRectMake(10, 230, 394, 50);
    [_nextButton addTarget:self action:@selector(clickNextButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_nextButton];
    /*********** 创建提示label ***********/
    self.labelOfHint = [[UILabel alloc] initWithFrame:CGRectMake(10, 290, 162.5, 30)];
    _labelOfHint.text = @"邮箱用户找回密码, 请";
    [self.view addSubview:_labelOfHint];
    /*********** 创建点击这里BUtton ***********/
    self.clickButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_clickButton setTitle:@"点击这里" forState:UIControlStateNormal];
    [_clickButton setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    _clickButton.titleLabel.font = [UIFont systemFontOfSize:18];
    _clickButton.frame = CGRectMake(172, 290, 72, 30);
    
    [self.view addSubview:_clickButton];
}
#pragma mark - button点击事件
- (void)clickNextButton:(UIButton *)button {
    //模态
//    [self dismissViewControllerAnimated:YES completion:nil];
    // pop
    [self.navigationController popToRootViewControllerAnimated:YES];
}
#pragma mark - 变色效果
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        _phoneNumber_image.image = [UIImage imageNamed:@"Unknown-1"];
    } else {
        _securityCode_image.image = [UIImage imageNamed:@"Unknown-3"];
    }
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        _phoneNumber_image.image = [UIImage imageNamed:@"Unknown"];
    } else {
        _securityCode_image.image = [UIImage imageNamed:@"Unknown-2"];
    }
    return YES;
}
//隐藏键盘(协议方法)
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
#pragma mark - 实现点击空白出键盘回收
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
